package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.BaseCompany;
import com.ruoyi.system.service.IBaseCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 单位基础Controller
 *
 * @author ruoyi
 * @date 2022-10-09
 */
@RestController
@RequestMapping("/company")
public class BaseCompanyController extends BaseController
{
    @Autowired
    private IBaseCompanyService baseCompanyService;

    /**
     * 查询单位基础列表
     */
    @RequiresPermissions("system:company:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseCompany baseCompany)
    {
        startPage();
        List<BaseCompany> list = baseCompanyService.selectBaseCompanyList(baseCompany);
        return getDataTable(list);
    }

    /**
     * 导出单位基础列表
     */
    @RequiresPermissions("system:company:export")
    @Log(title = "单位基础", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseCompany baseCompany)
    {
        List<BaseCompany> list = baseCompanyService.selectBaseCompanyList(baseCompany);
        ExcelUtil<BaseCompany> util = new ExcelUtil<BaseCompany>(BaseCompany.class);
        util.exportExcel(response, list, "单位基础数据");
    }

    /**
     * 获取单位基础详细信息
     */
    @RequiresPermissions("system:company:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseCompanyService.selectBaseCompanyById(id));
    }

    /**
     * 新增单位基础
     */
    @RequiresPermissions("system:company:add")
    @Log(title = "单位基础", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseCompany baseCompany)
    {
        return toAjax(baseCompanyService.insertBaseCompany(baseCompany));
    }

    /**
     * 修改单位基础
     */
    @RequiresPermissions("system:company:edit")
    @Log(title = "单位基础", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseCompany baseCompany)
    {
        return toAjax(baseCompanyService.updateBaseCompany(baseCompany));
    }

    /**
     * 删除单位基础
     */
    @RequiresPermissions("system:company:remove")
    @Log(title = "单位基础", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseCompanyService.deleteBaseCompanyByIds(ids));
    }
}
